package org.triumphxx.springboot.loopretry.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;

import javax.annotation.PostConstruct;

/**
 * @author: wangyp
 * @Date: 2023/7/18
 * @Time: 13:43
 * @Desc: 监听器 Bean，必须实现RetryListener
 **/
@Slf4j
public class RetryListenerBean implements RetryListener {

    @Override
    public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
        log.info("执行了 open 方法 ");
        return true;
    }

    @Override
    public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
        log.info("执行了 onError 方法，说明出现了异常");
    }

    @Override
    public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
        log.info("执行了 close 方法 ");
    }


}
